﻿@using Smartstore.Web.Models.Customers;

@model CustomerAvatarModel

@{
    if (!Model.AvatarColor.HasValue())
    {
        Model.AvatarColor = "light";
    }

    var canViewProfile = Model.AllowViewingProfiles && !(Request?.RouteValues?.IsSameRoute("Identity", "CustomerProfile") ?? false);
    var textColor = Model.AvatarColor == "light" ? "text-muted" : "text-light";

    async Task Avatar()
    {
        if ((Model.FileId ?? 0) != 0)
        {
            <img class="avatar-img" attr-class='(Model.DisplayRing, "avatar-ring")' src="@await Url.MediaAsync(Model.FileId, Model.AvatarPictureSize, null, false)" title="@Model.UserName" />
            <span class="avatar-letter d-none bg-@(Model.AvatarColor) @(textColor)" title="@Model.UserName">
                @Model.AvatarLetter
            </span>
        }
        else
        {
            <img class="avatar-img d-none" src="" title="@Model.UserName" />
            <span class="avatar-letter bg-@(Model.AvatarColor) @(textColor)" title="@Model.UserName" attr-style='(!canViewProfile, "cursor: default")'>
                @Model.AvatarLetter
            </span>
        }
    }
}

<div class="@(Model.Large ? "customer-avatar-lg" : "customer-avatar")">
    @if (canViewProfile)
    {
        <a class="avatar-link" asp-route="CustomerProfile" asp-route-id="@Model.Id">
            @{ await Avatar(); }
        </a>
    }
    else
    {
        await Avatar();
    }
</div>